﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_TraAddproduct : System.Web.UI.Page
{
    public string _strProjectId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
　　　　System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            _strProjectId = SysFun.IsSQL(Request.QueryString["projectid"]);
            if (Request.Form["SubSave"] == "添　加")
            {
                string goodsid = "";
                string  strSql;
                goodsid = SysFun.ToTrim(Request.Form["chkIsbid"]);
                Db db = new Db();
                if (goodsid != "")
                {
                    strSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,PS_ChangeStatus) select ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB,AccountId_tb as  AccountId_PS, CompanyName_tb as CompanyName_PS,BidPrice,'0',UserCode_TB,UserCode_tb as UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName,0  from TradeDataList where projectid=" + _strProjectId + " and isbid='1' and goodsid in(" + goodsid + ") and goodsid not in(select goodsid from SupplyPlan_Goods where ProjectId =" + _strProjectId + ")";
                    db.Command(strSql,30);
                    Response.Write("<script>alert('添加成功！');</script>");
                    
                }
                db.Close();

            }
            showGridView();
        }
    }
    public void showGridView()
    {
        int i = 0;
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "Bid_goods_product_cs_tb_agent";  //要查询的表名
        dbPage.Key = "bidid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "bidid,goodsid,ProductCode,ProductName,Outlookc,Medicinemodel,Factor,Unit+'/'+PACKUNIT AS PACK, CASE QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " END AS QualityLevels,UserCode_SC,CompanyName_SC,UserCode_TB,CompanyName_TB,SPPrice,LimitPrice*factor as limitprice,IsBid,SecondPrice ,ThirdPrice, MEMO10,bidprice";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        
            dbPage.PageSize = 10;                                                    //没有显示记录条数   
       
        dbPage.OrderBy = "ProductCode,QualityLevels,bidid";//排序字段


        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_table'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' >商品流水号</td>");
        strHtml.Append("<td class='table_title' >药品编码</td>");
        strHtml.Append("<td class='table_title' >通用名</td>");
        strHtml.Append("<td class='table_title' >剂型</td>");
        strHtml.Append("<td class='table_title' >规格</td>");
        strHtml.Append("<td class='table_title' >转换系数</td>");
        strHtml.Append("<td class='table_title' >包装</td>");
        strHtml.Append("<td class='table_title' >质量层次</td>");
        strHtml.Append("<td class='table_title' >生产企业名称</td>");
        strHtml.Append("<td class='table_title' >注册号</td>");
        strHtml.Append("<td class='table_title' >投标人</td>");
        strHtml.Append("<td class='table_title' >注册号</td>");
        strHtml.Append("<td class='table_title' >限价</td>");
        strHtml.Append("<td class='table_title' >投标报价</td>");
        strHtml.Append("<td class='table_title' >限价报价</td>");
        strHtml.Append("<td class='table_title' >竞价报价</td>");
        strHtml.Append("<td class='table_title' >中标价</td>");
     
        strHtml.Append("<td class='table_title' >选择</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader(60);
        while (dr.Read())
        {
            if (i == 0)
            {
                strHtml.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
                i--;
            }
            strHtml.Append("<td>" + dr["goodsid"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Factor"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["pack"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["QualityLevels"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["CompanyName_SC"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["UserCode_SC"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["CompanyName_TB"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["UserCode_TB"].ToString() + "</td>");
            strHtml.Append("<td>" + SysFun.ToDec(dr["LimitPrice"].ToString()).ToString("0.00") + "</td>");
            strHtml.Append("<td>" + SysFun.ToDec(dr["SPPrice"].ToString()).ToString("0.00") + "</td>");
            strHtml.Append("<td>" + SysFun.ToDec(dr["SecondPrice"].ToString()).ToString("0.00") + "</td>");
            strHtml.Append("<td>" + SysFun.ToDec(dr["ThirdPrice"].ToString()).ToString("0.00") + "</td>");
            strHtml.Append("<td>" + SysFun.ToDec(dr["bidprice"].ToString()).ToString("0.00") + "</td>");
            strHtml.Append("<td><input type='checkbox' name='chkIsbid' Value='" + dr["goodsid"].ToString() + "'  /></td>");
            strHtml.Append("</tr>");
        }　
        strHtml.Append("</table>");
         Label1.Text = strHtml.ToString();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp, _GoodsId;

        strtemp = " projectid=" + _strProjectId + " and isbid=1 and checkstatus=1 and bidprice >0 and goodsid not in (select goodsid from SupplyPlan_Goods where ProjectId =" + _strProjectId + ") and";

        //流水号
        _GoodsId = SysFun.ToTrim(txtGoodsId.Text);
        if (_GoodsId != "")
        {
            strtemp += " GoodsId like '%" + _GoodsId + "%' and";
        }

        //生产企业名称
        string _strCompanyName_SC = SysFun.ToTrim(txtSC.Text);
        if (_strCompanyName_SC != "")
        {
            strtemp += " CompanyName_SC like '%" + _strCompanyName_SC + "%' and";
        }

        //药品编码
        string _strProductCode = ProductCode.Text.ToString().Trim();
        if (_strProductCode != "")
        {
            strtemp += " ProductCode like '%" + _strProductCode + "%' and";
        }

        //药品名称
        string _strProductName = ProductName.Text.ToString().Trim();
        if (_strProductName != "")
        {
            strtemp += " (ProductName like '%" + _strProductName + "%'or SpellingCode like '%" + _strProductName + "%') and";
        }

        //规格
        string _strOutlookc = Outlookc.Text.ToString().Trim();
        if (_strOutlookc != "")
        {
            strtemp += " Outlookc like '%" + _strOutlookc + "%' and";
        }

        //投标人名称
        string _strCompanyName_TB = SysFun.ToTrim(txtCompanyName_TB.Text);
        if (_strCompanyName_TB != "")
        {
            strtemp += " CompanyName_TB like '%" + _strCompanyName_TB + "%' and";
        }

        //投标人注册号
        string _strUserCode_TB = txtCompanyUserCode.Text.ToString().Trim();
        if (_strUserCode_TB != "")
        {
            strtemp += " UserCode_TB='" + _strUserCode_TB + "' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }

}
